﻿Option Explicit On
Option Strict On

Imports Microsoft.Xna.Framework.Input

Public Class decisionClass

    'Create a new commands class, this is used for keyboard and mouse commands
    Private commands As New CommandsClass

    Public Event stopPolling()

    Public Sub buttonStateChanged(ByVal Button As Integer, ByVal TriggerType As Integer)

        'Button(s) on the controller has been pressed, held, or released
        Select Case TriggerType

            Case Is = gamePadClass.TriggerType.ShortPress
                'Button was held for less than 1 second and released

                Select Case Button

                    Case Is = Buttons.A
                        commands.PressAndReleaseKey(Keys.Enter)

                    Case Is = Buttons.B
                        commands.PressAndReleaseKey(Keys.Apps)

                    Case Is = Buttons.X
                        commands.PressAndReleaseKey(Keys.MediaPlayPause)

                    Case Is = Buttons.Y
                        commands.PressAndReleaseKey(Keys.MediaStop)

                    Case Is = Buttons.LeftShoulder
                        commands.PressAndReleaseKey(Keys.VolumeDown)

                    Case Is = Buttons.RightShoulder
                        commands.PressAndReleaseKey(Keys.VolumeUp)

                    Case Is = Buttons.LeftTrigger
                        'UNUSED

                    Case Is = Buttons.RightTrigger
                        'UNUSED

                    Case Is = Buttons.Back
                        commands.PressAndReleaseKey(Keys.Back)

                    Case Is = Buttons.Start
                        commands.PressKey(CType(18, Keys)) 'Keys.Menu)
                        commands.PressKey(Keys.LeftWindows)
                        commands.PressKey(Keys.Enter)
                        commands.ReleaseKey(Keys.Enter)
                        commands.ReleaseKey(Keys.LeftWindows)
                        commands.ReleaseKey(CType(18, Keys)) 'Keys.Menu)

                    Case Is = Buttons.LeftStick
                        'UNUSED

                    Case Is = Buttons.RightStick
                        'UNUSED

                    Case Is = Buttons.DPadUp
                        commands.PressAndReleaseKey(Keys.Up)

                    Case Is = Buttons.DPadRight
                        commands.PressAndReleaseKey(Keys.Right)

                    Case Is = Buttons.DPadDown
                        commands.PressAndReleaseKey(Keys.Down)

                    Case Is = Buttons.DPadLeft
                        commands.PressAndReleaseKey(Keys.Left)

                    Case Is = Buttons.LeftThumbstickUp
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickDown
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickRight
                        'UNUSED

                    Case Is = Buttons.RightThumbstickUp
                        'UNUSED

                    Case Is = Buttons.RightThumbstickDown
                        'UNUSED

                    Case Is = Buttons.RightThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.RightThumbstickRight
                        'UNUSED

                End Select


            Case Is = gamePadClass.TriggerType.LongPress
                'Button was held for more than 1 second and released

                Select Case Button
                    Case Is = Buttons.A
                        'UNUSED

                    Case Is = Buttons.B
                        commands.PressKey(CType(18, Keys)) 'Keys.Menu)
                        commands.PressKey(Keys.F4)
                        commands.ReleaseKey(Keys.F4)
                        commands.ReleaseKey(CType(18, Keys)) 'Keys.Menu)

                    Case Is = Buttons.X
                        'UNUSED

                    Case Is = Buttons.Y
                        'UNUSED

                    Case Is = Buttons.LeftShoulder
                        'UNUSED

                    Case Is = Buttons.RightShoulder
                        'UNUSED

                    Case Is = Buttons.LeftTrigger
                        'UNUSED

                    Case Is = Buttons.RightTrigger
                        'UNUSED

                    Case Is = Buttons.Back
                        RaiseEvent stopPolling()

                    Case Is = Buttons.Start
                        Process.Start("taskmgr.exe")

                    Case Is = Buttons.LeftStick
                        'UNUSED

                    Case Is = Buttons.RightStick
                        'UNUSED

                    Case Is = Buttons.DPadUp
                        'UNUSED

                    Case Is = Buttons.DPadRight
                        'UNUSED

                    Case Is = Buttons.DPadDown
                        'UNUSED

                    Case Is = Buttons.DPadLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickUp
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickDown
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickRight
                        'UNUSED

                    Case Is = Buttons.RightThumbstickUp
                        'UNUSED

                    Case Is = Buttons.RightThumbstickDown
                        'UNUSED

                    Case Is = Buttons.RightThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.RightThumbstickRight
                        'UNUSED

                End Select


            Case Is = gamePadClass.TriggerType.Hold
                'Button was held and hasn't been released

                Select Case Button
                    Case Is = Buttons.A
                        'UNUSED

                    Case Is = Buttons.B
                        'UNUSED

                    Case Is = Buttons.X
                        'UNUSED

                    Case Is = Buttons.Y
                        'UNUSED

                    Case Is = Buttons.LeftShoulder
                        'UNUSED

                    Case Is = Buttons.RightShoulder
                        'UNUSED

                    Case Is = Buttons.LeftTrigger
                        commands.activateMouseButton(CommandsClass.MouseActions.LeftDown)

                    Case Is = Buttons.RightTrigger
                        commands.activateMouseButton(CommandsClass.MouseActions.RightDown)

                    Case Is = Buttons.Back
                        'UNUSED

                    Case Is = Buttons.Start
                        'UNUSED

                    Case Is = Buttons.LeftStick
                        'UNUSED

                    Case Is = Buttons.RightStick
                        'UNUSED

                    Case Is = Buttons.DPadUp
                        'UNUSED

                    Case Is = Buttons.DPadRight
                        'UNUSED

                    Case Is = Buttons.DPadDown
                        'UNUSED

                    Case Is = Buttons.DPadLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickUp
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickDown
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickRight
                        'UNUSED

                    Case Is = Buttons.RightThumbstickUp
                        'UNUSED

                    Case Is = Buttons.RightThumbstickDown
                        'UNUSED

                    Case Is = Buttons.RightThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.RightThumbstickRight
                        'UNUSED
                End Select


            Case Is = gamePadClass.TriggerType.Release
                'Button was released that was previously held

                Select Case Button
                    Case Is = Buttons.A
                        'UNUSED

                    Case Is = Buttons.B
                        'UNUSED

                    Case Is = Buttons.X
                        'UNUSED

                    Case Is = Buttons.Y
                        'UNUSED

                    Case Is = Buttons.LeftShoulder
                        'UNUSED

                    Case Is = Buttons.RightShoulder
                        'UNUSED

                    Case Is = Buttons.LeftTrigger
                        commands.activateMouseButton(CommandsClass.MouseActions.LeftUp)

                    Case Is = Buttons.RightTrigger
                        commands.activateMouseButton(CommandsClass.MouseActions.RightUp)

                    Case Is = Buttons.Back
                        'UNUSED

                    Case Is = Buttons.Start
                        'UNUSED

                    Case Is = Buttons.LeftStick
                        'UNUSED

                    Case Is = Buttons.RightStick
                        'UNUSED

                    Case Is = Buttons.DPadUp
                        'UNUSED

                    Case Is = Buttons.DPadRight
                        'UNUSED

                    Case Is = Buttons.DPadDown
                        'UNUSED

                    Case Is = Buttons.DPadLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickUp
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickDown
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.LeftThumbstickRight
                        'UNUSED

                    Case Is = Buttons.RightThumbstickUp
                        'UNUSED

                    Case Is = Buttons.RightThumbstickDown
                        'UNUSED

                    Case Is = Buttons.RightThumbstickLeft
                        'UNUSED

                    Case Is = Buttons.RightThumbstickRight
                        'UNUSED
                End Select

        End Select

    End Sub

    Public Sub ThumbStickMoved(ByVal tStick As gamePadClass.gPadControl, ByVal X As Single, ByVal Y As Single)

        'If tStick = gamePadClass.gPadControl.Left Then

        commands.MoveCursor(CInt(15 * X), CInt(-15 * Y))

        'ElseIf tStick = gamePadClass.gPadControl.Right Then

        '    commands.MoveCursor(CInt(15 * X), CInt(-15 * Y))

        'End If

    End Sub

End Class
